package com.http;

import javax.servlet.http.HttpServletRequest;

import com.http.ClientInfo;

public class ClientInfo {
	
	public static ClientInfo EMPTY_CLIENT_INFO = new ClientInfo();
    private final String serverIpAddress;
    private final String clientIpAddress;

	private ClientInfo()
    {
        this(((String) (null)), null);
    }

    public ClientInfo(HttpServletRequest request)
    {
        this(request.getLocalAddr(), request.getRemoteAddr());
    }

    public ClientInfo(HttpServletRequest request, String alternateLocation)
    {
        this(request.getLocalAddr(), request.getHeader(alternateLocation) == null ? request.getRemoteAddr() : request.getHeader(alternateLocation));
    }

    public ClientInfo(String serverIpAddress, String clientIpAddress)
    {
        this.serverIpAddress = serverIpAddress != null ? serverIpAddress : "unknown";
        this.clientIpAddress = clientIpAddress != null ? clientIpAddress : "unknown";
    }

    public String getServerIpAddress()
    {
        return serverIpAddress;
    }

    public String getClientIpAddress()
    {
        return clientIpAddress;
    }

}
